<?php
if ($argc < 2) {
	print "$argv[0]: classes1.php [, ...]\n";
	exit;
}

// Include the files
foreach (array_slice($argv, 1) as $filename) {
	include_once $filename;
}

// Get all the method and function information
// Start with the classes
$methods = array();
foreach (get_declared_classes() as $class) {
	$r = new ReflectionClass($class);
	// Eliminate built-in classes
	if ($r->isUserDefined()) {
		foreach ($r->getMethods() as $method) {
			// Eliminate inherited methods
			if ($method->getDeclaringClass()->getName() == $class) {
				$signature = "$class::" . $method->getName();
				$methods[$signature] = $method;
			}
		}
	}
}

// Then add the functions
$functions = array();
$defined_functions = get_defined_functions();
foreach ($defined_functions['user'] as $function) {
	$functions[$function] = new ReflectionFunction($function);
}

// Sort methods alphabetically by class
function sort_methods($a, $b) {
	list ($a_class, $a_method) = explode('::', $a);
	list ($b_class, $b_method) = explode('::', $b);

	if ($cmp = strcasecmp($a_class, $b_class)) { 
		return $cmp;
	}

	return strcasecmp($a_method, $b_method);
}
uksort($methods, 'sort_methods');

// Sort functions alphabetically
// This is less complicated, but don't forget to 
// remove the method sorting function from the list
unset($functions['sort_methods']);
// Sort 'em
ksort($functions);

// Print out information
foreach (array_merge($functions, $methods) as $name => $reflect) {
	$file = $reflect->getFileName();
	$line = $reflect->getStartLine();
	 
	printf ("%-25s | %-40s | %6d\n", "$name()", $file, $line);
}
?>